<?php
class AShopTheme extends CActiveRecord{
    public static function model($className = __CLASS__) {
        return parent::model ( $className );
    }


    // goi den bang can ket noi   
    public function tableName() {                  
        return 'c_shop_themes';
    }
    
    public function getDataById($id){
        $sql = "SELECT * FROM c_shop_themes WHERE id = ".intval($id);
        $connect = Yii::app()->db;
        $command = $connect->createCommand($sql);
        $data = $command->queryRow();
        return $data;
    }

    public function getDataTheme($theme_name,$theme_path,$page,$row_per_page){
        $str_sql = "";
        if($theme_name){
            $str_sql .= " AND theme_name = '".mysql_escape_string($theme_name)."'";
        }
        if($theme_path){
            $str_sql .= " AND theme_path = '".mysql_escape_string($theme_path)."'";
        }
         $connect = Yii::app()->db;
        $sql = "SELECT count(id) as count FROM c_shop_themes WHERE 1 ".$str_sql."";
        $command = $connect->createCommand($sql);
        $data_count = $command->queryRow();
        $max_page = ceil(intval($data_count["count"])/$row_per_page);
        $first = ($page - 1)*$row_per_page;

        $sql = "SELECT * FROM c_shop_themes WHERE 1 ".$str_sql." ORDER BY id DESC LIMIT ".$first.",".$row_per_page."";
        $command = $connect->createCommand($sql);
        $data = $command->queryAll();
        return array($max_page,intval($data_count["count"]),$data);
    }

    
}
